package com.qiwx.pigeon.fragment;

import android.content.Intent;

import com.qiwx.pigeon.Utils.DBSqlUtil;
import com.qiwx.pigeon.Utils.DateTimeUtils;
import com.qiwx.pigeon.Utils.LogUtil;
import com.qiwx.pigeon.Utils.MyToast;
import com.qiwx.pigeon.activity.common.SelectDateActivity;
import com.qiwx.pigeon.app.AppContext;
import com.qiwx.pigeon.base.BaseFragment;
import com.qiwx.pigeon.base.BaseMVPFragment;
import com.qiwx.pigeon.base.Constant;
import com.qiwx.pigeon.data.vo.WareHouseBean;
import com.qiwx.pigeon.presenter.OperatePresenter;
import com.qiwx.pigeon.viewinterface.IOperateView;

import java.util.ArrayList;
import java.util.List;

import static com.qiwx.pigeon.activity.common.SelectDateActivity.REQUEST_CODE_END;
import static com.qiwx.pigeon.activity.common.SelectDateActivity.REQUEST_CODE_START;

/**
 * @description
 * @Author qiwx
 * @Date 2020-03-28 17:08
 * 带有数据库查询相关方法
 **/
public abstract class AbsQueryFragment extends BaseFragment {

    List<WareHouseBean> data = new ArrayList<>();

    //选择有效期
    public void selectStartValiDate() {
        Intent intent = new Intent(getActivity(), SelectDateActivity.class);
//        intent.putExtra("term", 3);
        intent.putExtra("MinMonth", DateTimeUtils.getMonth4String("1990-01"));
        intent.putExtra("Minyear", DateTimeUtils.getYear4String("1990-01"));

        intent.putExtra(Constant.KEY_TITLE, "开始日期");
        startActivityForResult(intent, REQUEST_CODE_START);
    }

    public void selectEndValiDate(String startDate) {
        if (startDate == null || startDate.equals("")) {
            MyToast.showShort("先选择开始日期");
            return;
        }
        startDate = startDate.replace("年", "")
                .replace("日", "");

        String[] arr = startDate.split("-");
        Intent intent = new Intent(getActivity(), SelectDateActivity.class);
//        intent.putExtra("term", 3);
        intent.putExtra("Minyear", arr[0]);
        intent.putExtra("MinMonth", arr[1]);
        intent.putExtra(Constant.KEY_TITLE, "结束日期");
        startActivityForResult(intent, REQUEST_CODE_END);
    }

    public List<WareHouseBean> getWareHouses() {
        data.clear();
        data.addAll(AppContext.houses);
        return data;
    }

    //刷新数据
    public void onReFreshData() {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        LogUtil.e("TAG", "fragment销毁" + getClass().getSimpleName());
    }
}
